package com.niit.project.controller;

import com.niit.project.entity.Admin;
import com.niit.project.entity.BadGoods;
import com.niit.project.entity.Page;
import com.niit.project.service.BadGoodsService;
import com.niit.project.service.impl.BadGoodsServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.*;
import javax.servlet.http.*;
import java.io.IOException;
import java.util.List;

//张雨佳——管理员页面显示举报信息
@WebServlet(name = "ShowAllBadGoodsServlet", value = "/ShowAllBadGoodsServlet")
public class ShowAllBadGoodsServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //分页查询
        String pageIndex = request.getParameter("pageIndex");
        if(pageIndex == null)
        {
            pageIndex = "1";
        }

        //创建分页对象
        Page page = new Page(Integer.valueOf(pageIndex));

        BadGoodsService badGoodsService = new BadGoodsServiceImpl();

        //将分页查询的结果存入list类型的集合对象badGoods中
        List<BadGoods> badGoods = badGoodsService.showAllByPage(page);
        HttpSession session = request.getSession();
        Admin admin = (Admin) session.getAttribute("admin");
        request.setAttribute("badgoods",badGoods);
        request.setAttribute("page",page);
        //转发,将请求中的数据传入前端页面
        request.getRequestDispatcher("/mailbox.jsp").forward(request,response);
    }
}
